﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreRay
{
    public class DifferentialGeometry
    {
        public DifferentialGeometry(Vector3 position, Vector3 dpdu, Vector3 dpdv, Vector3 normal, Vector2 textureCoordinates)
        {
            this.Position = position;
            this.Normal = normal;
            //this.Normal = Vector3.CrossProduct(dpdv, dpdu);

            this.Dpdu = dpdu;
            this.Dpdv = dpdv;
            this.TextureCoordinates = textureCoordinates;
        }

        public Vector3 Position
        {
            get;
            private set;
        }

        public Vector3 Normal
        {
            get;
            private set;
        }

        public Vector3 Dpdu
        {
            get;
            private set;
        }

        public Vector3 Dpdv
        {
            get;
            private set;
        }

        public Vector2 TextureCoordinates
        {
            get;
            private set;
        }

        public void TransformToWorldSpace(Matrix worldMatrix, Matrix inverseWorldMatrix)
        {
            this.Position = this.Position * worldMatrix;
            this.Normal = Matrix.MultiplyNormal(this.Normal, inverseWorldMatrix).Normalize();

            // TO REVIEW: Transform normal
        }
    }
}
